import java.net.*;

/**
 * The PolicyServer waits for client connections and uses PolicyServerConnections to handle policy requests.
 */
public class PolicyServer {

    public static final String POLICY_REQUEST = "<policy-file-request/>";
    public static final String POLICY_REPLY =
            "<?xml version=\"1.0\"?>"
    		+ "<!DOCTYPE cross-domain-policy SYSTEM \"http://www.adobe.com/xml/dtds/cross-domain-policy.dtd\">"
            + "<cross-domain-policy>"
            + "<allow-access-from domain=\"*\" to-ports=\"25432\" />"
            + "</cross-domain-policy>";
        
    /**
     * Main Entry Point
     */
    public static void main(String[] args) {
        try {
            ServerSocket serverSocket = new ServerSocket(843);
            System.out.println("Policy Server Listening on 843");
            
            while (true) {
                Socket socket = serverSocket.accept();
                System.out.println("Opening policy connection from: " + socket.getRemoteSocketAddress());
                PolicyServerConnection newConnection = new PolicyServerConnection(socket);
                newConnection.start();
            }
        }
        catch (Exception e) {
            System.out.println("Exception: " + e.getMessage());
        }
    }
}
